home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 05 / 6 / DISK0564.ZIP / SOURCE.ARC / RW.C < prev    next >
C/C++ Source or Header  |  1986-04-10  |  2KB  |  69 lines

  1. /* this program write-enables (unprotects) one or more files */
  2. /* for MSDOS Version 2 or higher */
  3. /* usage: ro file1 file2 ... */
  4. /* file name can be ambiguous */
  5. /* for Aztec C86 v. 3.20e */
  6. /* by Jon Dart, 29-Mar-1986 */
  7.  
  8. #define Version "1.1 (10-Apr-86)"
  9.  
  10. #include "stdio.h"
  11. #include "fixpath.h"
  12. #include "sgtty.h"
  13. #include "ctype.h"
  14. #include "truth.h"
  15. #include "ascii.h"
  16.  
  17. #define PATHSIZE 128
  18. #define ROBIT   0x0001
  19. #define DIRBIT  0x0010
  20.  
  21. extern char *malloc();
  22. static char *sp,*lip,*fn, *fn2;
  23. static int attrib;
  24.  
  25. rw(fn)
  26. char *fn;
  27. {
  28.     if ((attrib & (DIRBIT+ROBIT))==ROBIT) {
  29.     /* not a directory and not already r/w */
  30.        if (chmod(fn,(attrib & ~ROBIT) & 0xFF) == -1)
  31.            printf("%s: can't change attribute.\n",fn2);
  32.     }
  33. }
  34.  
  35. main(argc,argv)
  36. int argc; char *argv[];
  37. {
  38.     int n;
  39.  
  40.     sp = malloc(PATHSIZE);
  41.     lip = malloc(PATHSIZE);
  42.     fn = malloc(PATHSIZE);
  43.     fn2 = malloc(PATHSIZE);
  44.     if (argc<=1) {
  45.         fprintf(stderr,"rw -- makes files read/write (unprotects them)\n");
  46.         fprintf(stderr,"%s%s\n\n","by Jon Dart ... Version ",Version);
  47.         fprintf(stderr,"Usage:\n    rw file1 file2 ....\n");
  48.         fprintf(stderr,"    (file names can be ambiguous)\n");
  49.         exit(1);
  50.     }
  51.     for (n=1;n<argc;n++) {
  52.         fixpath(argv[n],sp,lip);
  53.         if (getfirst(sp,0x21,fn,&attrib)) {
  54.             strcpy(fn2,lip);
  55.             strcat(fn2,fn);
  56.             rw(fn2);
  57.             while (getnext(fn,&attrib)) {
  58.                 strcpy(fn2,lip);
  59.                 strcat(fn2,fn);
  60.                 rw(fn2);
  61.             }
  62.         }
  63.         else {
  64.             fprintf(stderr,"%s%s\n","Error - can't find: ",argv[n]);
  65.         }
  66.     }
  67. }
  68.  
  69.